<?php
App::uses('AppModel', 'Model');
/**
 * Setting Model
 *
 */
class Setting extends AppModel {
/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'value';
        
        public function addNewSetting($data) {
            $this->create();
            if ($this->save($data)) {
                return true;
            } else {
                return false;
            }
        }
        public function getValue($key) {
            $val = $this->find('first', array('conditions' => array('key' => $key), 'recursive' => -1));
            return $val['Setting']['value'];
        }
        public function getPricePlan($plan) {
            switch ($plan) {
                case 1:
                    $plan_price_key = ONE_MONTH;
                    break;
                case 3:
                    $plan_price_key = THREE_MONTHS;
                    break;
                case 6:
                    $plan_price_key = SIX_MONTHS;
                    break;
                case 12:
                default:
                    $plan_price_key = TWELVE_MONTHS;
                    break;
            }
            return $this->getValue($plan_price_key);
        }
        
        public function getCompany() {
            $company = $this->find('all', array('conditions' => array('Setting.option' => COMPANY_INFO_KEY)));
            
            $value = '';
            foreach($company as $com) {
                $value[$com['Setting']['key']] = $com['Setting']['value'];
            }
            return $value;
        }
        public function setCompany($data) {
            
            foreach($data as $key => $val) {
                $this->updateAll(
                        array('Setting.value' => "'$val'"),
                        array('Setting.key' => $key)
                        );
            }
        }
}
